<template>
  <div>
    <div>
      <el-row>
        <el-button
          type="primary"
          class="el-icon-arrow-left"
          size="small"
          @click="toback()"
          >返回</el-button
        >
      </el-row>
    </div>

    <!-- 分割线 -->
    <div>
      <el-divider><i class="el-icon-s-order" /></el-divider>
    </div>
    <div>
      <el-form :inline="true" :model="epdata" class="demo-form-inline">
        <el-form-item label="企业名称" :label-width="formLabelWidth">
          <el-input v-model="epdata.epname"></el-input>
        </el-form-item>
        <el-form-item label="社会信用代码" :label-width="formLabelWidth">
          <el-input v-model="epdata.epcode"></el-input>
        </el-form-item>
        <el-form-item label="行业类型" :label-width="formLabelWidth">
          <el-input v-model="epdata.epitype"></el-input>
        </el-form-item>
        <el-form-item label="企业成立时间" :label-width="formLabelWidth">
          <el-date-picker
            v-model="epdata.epetime"
            type="date"
            placeholder="选择日期"
            format="yyyy 年 MM 月 dd 日"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="地区" :label-width="formLabelWidth">
          <!-- 省市区三级联动插件 -->
          <div>
            <div id="app">
              <el-cascader
                size="large"
                :options="options"
                v-model="selectedOptions"
                @change="handleChange"
              >
              </el-cascader>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="详细地址" :label-width="formLabelWidth">
          <el-input v-model="address" placeholder="详细地址"></el-input>
        </el-form-item>
        <el-form-item label="员工人数" :label-width="formLabelWidth">
          <el-input v-model="epdata.epempnumber"></el-input>
        </el-form-item>

        <el-form-item label="注册资金" :label-width="formLabelWidth">
          <el-input v-model="epdata.epcapital"></el-input>
        </el-form-item>
        <el-form-item label="营业执照号" :label-width="formLabelWidth">
          <el-input v-model="epdata.epblnumber"></el-input>
        </el-form-item>
        <el-form-item label="企业类型" :label-width="formLabelWidth">
          <el-input v-model="epdata.eptype"></el-input>
        </el-form-item>

        <el-form-item label="法人姓名" :label-width="formLabelWidth">
          <el-input v-model="epdata.lpid.lpname"></el-input>
        </el-form-item>
        <el-form-item label="性别" :label-width="formLabelWidth">
          <el-input v-model="epdata.lpid.lpgender"></el-input>
        </el-form-item>
        <el-form-item label="证件类型" :label-width="formLabelWidth">
          <el-input v-model="epdata.lpid.lpdtype"></el-input>
        </el-form-item>
        <el-form-item label="证件号" :label-width="formLabelWidth">
          <el-input v-model="epdata.lpid.lpdnumber"></el-input>
        </el-form-item>
        <el-form-item label="手机号" :label-width="formLabelWidth">
          <el-input v-model="epdata.lpid.lpphonenumber"></el-input>
        </el-form-item>
        <el-form-item label="邮箱号" :label-width="formLabelWidth">
          <el-input v-model="epdata.lpid.lpemile"></el-input>
        </el-form-item>

        <el-form-item label="企业联系人姓名" :label-width="formLabelWidth">
          <el-input v-model="epdata.eccid.ecname"></el-input>
        </el-form-item>
        <el-form-item label="职务" :label-width="formLabelWidth">
          <el-input v-model="epdata.eccid.ecpost"></el-input>
        </el-form-item>
        <el-form-item label="联系电话" :label-width="formLabelWidth">
          <el-input v-model="epdata.eccid.ecphone"></el-input>
        </el-form-item>
        <el-form-item label="电子邮箱" :label-width="formLabelWidth">
          <el-input v-model="epdata.eccid.ecemile"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">保存</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { regionData, CodeToText, TextToCode } from "element-china-area-data";
export default {
  data() {
    return {
      formLabelWidth: "150px",
      address: "",
      options: regionData,
      selectedOptions: [],
      epdata: {
        epid: 0,
        epname: "", //企业名称
        epcode: "", //社会信用代码
        epitype: "", //行业类型
        epetime: "", //企业成立时间
        epcapital: 0, //注册资金
        epblnumber: "", //营业执照号
        eptype: "", //企业类型
        epempnumber: 0, //员工人数
        epaddress: "", //企业注册地址
        lpid: {
          // 法人
          lpid: 0,
          lpname: "", //法人姓名
          lpgender: "", //性别
          lpdtype: "", //证件类型
          lpdnumber: "", //证件号
          lpphonenumber: "", //手机号
          lpemile: "", //邮箱号
        },
        eccid: {
          //联系方式
          eccid: 0,
          ecname: "", //企业联系人姓名
          ecpost: "", //职务
          ecphone: "", //联系电话
          ecemile: "", //电子邮箱
        },
        epstate: 1, //黑名单状态 2-是，1-否（默认）
      },
    };
  },

  methods: {
    toback() {
      //跳转页面
      this.$router.push("/epinfo");
    },

    handleChange(value) {
      this.epdata.epaddress = '';
      console.log(value);

      //   遍历转换省市区得值
      value.forEach((element) => {
        this.epdata.epaddress += CodeToText[element];
      });
      console.log(this.epdata.epaddress);
    },

    onSubmit() {
      console.log("submit!");
      this.epdata.epaddress+=this.address;
      console.log(this.epdata)
      this.$axios
        .post("http://localhost:8082/enp/insertEp", this.epdata)
        .then((resp) => {
          console.log("新增成功");
          console.log(resp)
          if (resp.data.code==200) {
            this.$router.push("/epinfo");
            this.$message({
            message: "已保存",
            type: "success",
          });
          }
        });
      
    },
  },
};
</script>

<style>
</style>